package com.imooc.course.server.config.dao;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;

@SpringBootConfiguration
public class C3p0Config {


    @Bean(name = "data_Source")//指定当前对象作为bean
    @Qualifier(value = "data_Source")//指定dataSource来DI
    @Primary//primary将当前数据库连接池作为默认数据库连接池
    @ConfigurationProperties(prefix = "c3p0")//匹配application.properties或yml文件中前缀为c3p0的配置值
    public ComboPooledDataSource dataSource(){
        DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
        DataSourceBuilder<ComboPooledDataSource> builder = dataSourceBuilder.type(ComboPooledDataSource.class);
        return builder.build();
    }

}
